<?xml version="1.0"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
<xsl:output method="html" indent="yes"
        doctype-public="-//W3C//DTD HTML 4.01//EN"
        doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>jquery.growfield API</title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <link rel="stylesheet" href="doc.css" type="text/css"/>
            </head>
            <body>
                <div id="main">
                <div class="header">
                    <h1>jquery.growfield API</h1>
                </div>
                <br/>
                <xsl:if test="description">
                    <p class="description"><xsl:value-of select="description"/></p>
                </xsl:if>
                <xsl:apply-templates select="/growfield/api" mode="global"/>
                <div class="options">
                    <h2>Options</h2>
                    <table cellspacing="0">
                        <thead>
                            <tr>
                                <th></th>
                                <th class="optionName">Name</th>
                                <th class="optionFormat">Format</th>
                                <th class="optionDefault">Default</th>
                            </tr>
                        </thead>
                        <tbody>
                        <xsl:apply-templates select="//option">
                            <xsl:sort order="ascending" select="@name"/>
                        </xsl:apply-templates>
                        </tbody>
                    </table>
                </div>
                <xsl:apply-templates select="/growfield/note" mode="global"/>
                </div>
            </body>
        </html>
    </xsl:template>


    <xsl:template match="option">
        <tr>
        <xsl:if test="position() mod 2 = 0">
        <xsl:attribute name="class">even</xsl:attribute>
        </xsl:if>
            <td rowspan="2" class="optionPosition"><xsl:value-of select="position()"/>.</td>
            <td class="optionName"><h3><xsl:value-of select="@name"/></h3></td>
            <td class="optionFormat"><xsl:value-of select="@format"/></td>
            <td class="optionDefault"><xsl:value-of select="@default"/></td>
        </tr>
        <tr>
        <xsl:if test="position() mod 2 = 0">
        <xsl:attribute name="class">even</xsl:attribute>
        </xsl:if>
            <td colspan="3" class="optionDescr">
                <xsl:value-of select="description"/>
                <xsl:if test="value">
                    <ul class="values">
                    <xsl:apply-templates select="value"/>
                    </ul>
                </xsl:if>
                <xsl:apply-templates select="current()/note" mode="option"/>
                <xsl:if test="@restart = 1">
                    <p class="restart">* This option requires module restart</p>
                </xsl:if>
                <xsl:if test="@restart = 2">
                    <p class="restart">* Restarting the module is recommended</p>
                </xsl:if>
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="note" mode="option">
        <blockquote>
            <xsl:value-of select="."/>
        </blockquote>
    </xsl:template>

    <xsl:template match="note" mode="api">
        <blockquote>
            <xsl:value-of select="."/>
        </blockquote>
    </xsl:template>

    <xsl:template match="option/value">
        <li class="value">
            <b><xsl:value-of select="@type"/></b> -- <xsl:value-of select="."/>
        </li>
    </xsl:template>

    <xsl:template match="note" mode="global">
        <div class="note">
            <h3><xsl:value-of select="@name"/></h3>
            <xsl:copy-of select="."/>
        </div>
    </xsl:template>

    <xsl:template match="api" mode="global">
        <div class="api">
            <h2><xsl:value-of select="@name"/></h2>
            <div>
                <xsl:copy-of select="description"/>
            </div>
            <xsl:apply-templates select="current()/note" mode="api"/>
        </div>
    </xsl:template>
</xsl:stylesheet>